<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>div水平垂直居中示例</title>
    <style>
        /* 通用样式 */
        .demo-container {
            margin: 20px 0;
            border: 1px solid #ccc;
            height: 200px;
            position: relative;
        }
        .demo-title {
            padding: 5px;
            background-color: #f0f0f0;
            font-weight: bold;
        }
        .center-box {
            background-color: #3498db;
            color: white;
            text-align: center;
            width: 100px;
            height: 100px;
        }/*  */
        /* 方法1: Flexbox */
        .method1 {
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>
<body>
    <h3>div水平垂直居中的第一种方法</h3>
    <div class="demo-title">方法1: 弹性布局</div>
    <div class="demo-container method1">
        <div class="center-box">微信公众号前端小歌谣</div>
    </div>
</body>
</html>